package com.ibmeeting.modules.system.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ibmeeting.modules.system.domain.UUser;
import com.ibmeeting.modules.system.mapper.UUserMapper;
import com.ibmeeting.modules.system.service.UUserService;
import org.springframework.stereotype.Service;

/**
* @author 办会科技
* @description 针对表【u_user(用户端用户信息表)】的数据库操作Service实现
* @createDate 2025-04-21 15:01:29
*/
@Service
public class UUserServiceImpl extends ServiceImpl<UUserMapper, UUser>
    implements UUserService {

    @Override
    public boolean checkUserUnique(UUser sysUser) {
        // 检查手机号是否已存在
        boolean phoneExist = baseMapper.exists(new LambdaQueryWrapper<UUser>()
                .eq(UUser::getPhone, sysUser.getPhone())
                .ne(ObjectUtil.isNotNull(sysUser.getId()), UUser::getId, sysUser.getId()));

        // 检查邮箱是否已存在
        boolean emailExist = baseMapper.exists(new LambdaQueryWrapper<UUser>()
                .eq(UUser::getEmail, sysUser.getEmail())
                .ne(ObjectUtil.isNotNull(sysUser.getId()), UUser::getId, sysUser.getId()));

        // 如果手机号或邮箱已存在，则返回 false
        return !phoneExist && !emailExist;
    }
}




